#include <stdbool.h>
#include <iostream>
#include <assert.h>

#define rawtt(o)	((o)->tt_)
#define novariant(t)	((t) & 0x0F)
#define ttype(o)	(novariant(rawtt(o)))
#define LUA_TBOOLEAN		1
#define makevariant(t,v)  ((t) | ((v) << 4))
#define LUA_VFALSE	makevariant(LUA_TBOOLEAN, 0)
#define LUA_VTRUE	makevariant(LUA_TBOOLEAN, 1)
#define checktag(o,t)		(rawtt(o) == (t))
#define checktype(o,t)		(ttype(o) == (t))
#define ttisboolean(o)		checktype((o), LUA_TBOOLEAN)
#define ttisfalse(o)		checktag((o), LUA_VFALSE)
#define ttistrue(o)		checktag((o), LUA_VTRUE)

// 这里将Value先去掉
// #define TValuefields	Value value_; lu_byte tt_
typedef unsigned char lu_byte;
#define TValuefields lu_byte tt_
typedef struct TValue {
  TValuefields;
} TValue;

int main()
{
  {
    union intOrBoolean{
      bool bValue; // 1字节
      int iValue1; // 4字节
      double iValue2; // 8字节
    }t;
    t.bValue = true;
    t.iValue1 = 100; // 后面的会覆盖前面的

    std::cout<< sizeof(bool) << ":" << sizeof(int)<< ":" << sizeof(double) << std::endl;

    assert(sizeof(t) == 8);
  }

  {
    // 使用断点查看p1 p2的内存
    lu_byte bol1 = LUA_VFALSE;
    lu_byte bol2 = LUA_VTRUE;
    lu_byte* p1 = &bol1;
    lu_byte* p2 = &bol2;
  }

  {
    TValue my_true = {LUA_VTRUE};
    TValue my_false = {LUA_VFALSE};
    assert(ttisboolean(&my_true));
    assert(ttistrue(&my_true));
    assert(ttisfalse(&my_false));
  }
  
  int a = 0;
  std::cin >> a;
  return 0;
}